

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=dark>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/fluid.png">
  <link rel="icon" href="/img/icon/dw.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="Memory">
  <meta name="keywords" content="">
  
    <meta name="description" content="每天进步一点点，见证编程能力的蜕变过程">
<meta property="og:type" content="article">
<meta property="og:title" content="小程序开发经验分享：踩坑指南与技巧总结">
<meta property="og:url" content="http://example.com/2023/07/30/%E5%B0%8F%E7%A8%8B%E5%BA%8F%E5%BC%80%E5%8F%91%E7%BB%8F%E9%AA%8C%E5%88%86%E4%BA%AB%EF%BC%9A%E8%B8%A9%E5%9D%91%E6%8C%87%E5%8D%97%E4%B8%8E%E6%8A%80%E5%B7%A7%E6%80%BB%E7%BB%93/index.html">
<meta property="og:site_name" content="Memory&#39;s blog">
<meta property="og:description" content="每天进步一点点，见证编程能力的蜕变过程">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://example.com/img/artical/girl6.jpg">
<meta property="article:published_time" content="2023-07-30T10:42:15.000Z">
<meta property="article:modified_time" content="2023-08-09T14:14:12.000Z">
<meta property="article:author" content="Memory">
<meta property="article:tag" content="经验">
<meta property="article:tag" content="项目">
<meta property="article:tag" content="小程序">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="http://example.com/img/artical/girl6.jpg">
  
  
  
  <title>小程序开发经验分享：踩坑指南与技巧总结 - Memory&#39;s blog</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"example.com","root":"/","version":"1.9.4","typing":{"enable":true,"typeSpeed":100,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":false,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":true,"follow_dnt":true,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
  

  

  

  

  

  

  

  



  
<meta name="generator" content="Hexo 5.4.2"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 75vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>Memory&#39;s blog</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                <span>首页</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                <span>归档</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                <span>分类</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                <span>标签</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                <span>关于</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/links/">
                <i class="iconfont icon-link-fill"></i>
                <span>友链</span>
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              <i class="iconfont icon-search"></i>
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">
              <i class="iconfont icon-dark" id="color-toggle-icon"></i>
            </a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/img/newBG/girl.jpg') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="小程序开发经验分享：踩坑指南与技巧总结"></span>
          
        </div>

        
          
  <div class="mt-3">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-author" aria-hidden="true"></i>
        Memory
      </span>
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2023-07-30 18:42" pubdate>
          2023年7月30日 晚上
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          13k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          32 分钟
        
      </span>
    

    
    
      
        <span id="leancloud-page-views-container" class="post-meta" style="display: none">
          <i class="iconfont icon-eye" aria-hidden="true"></i>
          <span id="leancloud-page-views"></span> 次
        </span>
        
      
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar category-bar" style="margin-right: -1rem">
    





<div class="category-list">
  
  
    
    
    
    <div class="category row nomargin-x">
      <a class="category-item 
          list-group-item category-item-action col-10 col-md-11 col-xm-11" title="小程序"
        id="heading-0ed5103f88f9b3417c8cba24b8cc268d" role="tab" data-toggle="collapse" href="#collapse-0ed5103f88f9b3417c8cba24b8cc268d"
        aria-expanded="true"
      >
        小程序
        <span class="list-group-count">(1)</span>
        <i class="iconfont icon-arrowright"></i>
      </a>
      
      <div class="category-collapse collapse show" id="collapse-0ed5103f88f9b3417c8cba24b8cc268d"
           role="tabpanel" aria-labelledby="heading-0ed5103f88f9b3417c8cba24b8cc268d">
        
        
          
          
  <div class="category-post-list">
    
    
  </div>

          
  
    
    
    
    <div class="category-sub row nomargin-x">
      <a class="category-subitem 
          list-group-item category-item-action col-10 col-md-11 col-xm-11" title="项目"
        id="heading-31ecc0e65b4cd3e6b12577382bb56d6a" role="tab" data-toggle="collapse" href="#collapse-31ecc0e65b4cd3e6b12577382bb56d6a"
        aria-expanded="true"
      >
        项目
        <span class="list-group-count">(1)</span>
        <i class="iconfont icon-arrowright"></i>
      </a>
      
      <div class="category-collapse collapse show" id="collapse-31ecc0e65b4cd3e6b12577382bb56d6a"
           role="tabpanel" aria-labelledby="heading-31ecc0e65b4cd3e6b12577382bb56d6a">
        
        
          
          
  <div class="category-post-list">
    
    
  </div>

          
  
    
    
    
    <div class="category-sub row nomargin-x">
      <a class="category-subitem 
          list-group-item category-item-action col-10 col-md-11 col-xm-11" title="经验"
        id="heading-32a8e000e928e6dc255876d9fc0178b3" role="tab" data-toggle="collapse" href="#collapse-32a8e000e928e6dc255876d9fc0178b3"
        aria-expanded="true"
      >
        经验
        <span class="list-group-count">(1)</span>
        <i class="iconfont icon-arrowright"></i>
      </a>
      
      <div class="category-collapse collapse show" id="collapse-32a8e000e928e6dc255876d9fc0178b3"
           role="tabpanel" aria-labelledby="heading-32a8e000e928e6dc255876d9fc0178b3">
        
        
          
  <div class="category-post-list">
    
    
      
      
        <a href="/2023/07/30/%E5%B0%8F%E7%A8%8B%E5%BA%8F%E5%BC%80%E5%8F%91%E7%BB%8F%E9%AA%8C%E5%88%86%E4%BA%AB%EF%BC%9A%E8%B8%A9%E5%9D%91%E6%8C%87%E5%8D%97%E4%B8%8E%E6%8A%80%E5%B7%A7%E6%80%BB%E7%BB%93/" title="小程序开发经验分享：踩坑指南与技巧总结"
           class="list-group-item list-group-item-action
           active">
          <span class="category-post">小程序开发经验分享：踩坑指南与技巧总结</span>
        </a>
      
    
  </div>

        
      </div>
    </div>
  
        
      </div>
    </div>
  
        
      </div>
    </div>
  
</div>


  </aside>


    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">小程序开发经验分享：踩坑指南与技巧总结</h1>
            
              <p class="note note-success">
                
                  
                    本文最后更新于：10 个月前
                  
                
              </p>
            
            
              <div class="markdown-body">
                
                <h1 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h1><ul>
<li><h5 id="记录小程序开发过程中的问题"><a href="#记录小程序开发过程中的问题" class="headerlink" title="记录小程序开发过程中的问题"></a>记录小程序开发过程中的问题</h5></li>
</ul>
<h1 id="正文"><a href="#正文" class="headerlink" title="正文"></a>正文</h1><h2 id="小程序开发"><a href="#小程序开发" class="headerlink" title="小程序开发"></a>小程序开发</h2><h3 id="开发准备"><a href="#开发准备" class="headerlink" title="开发准备"></a>开发准备</h3><h4 id="HBuilderX-uni-app-uinCloud"><a href="#HBuilderX-uni-app-uinCloud" class="headerlink" title="HBuilderX+uni-app+uinCloud"></a>HBuilderX+uni-app+uinCloud</h4><ul>
<li><h5 id="uni-app官网-dcloud-net-cn"><a href="#uni-app官网-dcloud-net-cn" class="headerlink" title="uni-app官网 (dcloud.net.cn)"></a><a target="_blank" rel="noopener" href="https://uniapp.dcloud.net.cn/">uni-app官网 (dcloud.net.cn)</a></h5></li>
<li><h5 id="87条消息-为uni-cloud（Dcloud国产之辉）声明！-lqj-本人的博客-CSDN博客"><a href="#87条消息-为uni-cloud（Dcloud国产之辉）声明！-lqj-本人的博客-CSDN博客" class="headerlink" title="(87条消息) 为uni-cloud（Dcloud国产之辉）声明！_lqj_本人的博客-CSDN博客"></a><a target="_blank" rel="noopener" href="https://blog.csdn.net/lbcyllqj/article/details/131135791">(87条消息) 为uni-cloud（Dcloud国产之辉）声明！_lqj_本人的博客-CSDN博客</a></h5></li>
</ul>
<h4 id="微信开发者工具连接失败"><a href="#微信开发者工具连接失败" class="headerlink" title="微信开发者工具连接失败"></a>微信开发者工具连接失败</h4><p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20230803210244455.png" alt="image-20230803210244455"></p>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20230803210305939.png" alt="image-20230803210305939"></p>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20230803210317551.png" alt="image-20230803210317551"></p>
<h3 id="微信开发者工具"><a href="#微信开发者工具" class="headerlink" title="微信开发者工具"></a>微信开发者工具</h3><ul>
<li><h5 id="最近在开发-PicMemories壁纸分享小程序，浅浅记录遇到的一些问题"><a href="#最近在开发-PicMemories壁纸分享小程序，浅浅记录遇到的一些问题" class="headerlink" title="最近在开发 PicMemories壁纸分享小程序，浅浅记录遇到的一些问题"></a>最近在开发 PicMemories壁纸分享小程序，浅浅记录遇到的一些问题</h5></li>
</ul>
<h4 id="请求域名不合法"><a href="#请求域名不合法" class="headerlink" title="请求域名不合法"></a>请求域名不合法</h4><ul>
<li><h5 id="开发过程中，不校验合法域名："><a href="#开发过程中，不校验合法域名：" class="headerlink" title="开发过程中，不校验合法域名："></a>开发过程中，不校验合法域名：</h5></li>
</ul>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20230803192902265.png" alt="image-20230803192902265"></p>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20230803192858399.png" alt="image-20230803192858399"></p>
<ul>
<li><h5 id="小程序·不在以下-request-合法域名列表中及域名配置-菜鸟婷婷-博客园-cnblogs-com"><a href="#小程序·不在以下-request-合法域名列表中及域名配置-菜鸟婷婷-博客园-cnblogs-com" class="headerlink" title="小程序·不在以下 request 合法域名列表中及域名配置 - 菜鸟婷婷 - 博客园 (cnblogs.com)"></a><a target="_blank" rel="noopener" href="https://www.cnblogs.com/cntt/p/12988539.html">小程序·不在以下 request 合法域名列表中及域名配置 - 菜鸟婷婷 - 博客园 (cnblogs.com)</a></h5></li>
<li><h5 id="小程序合法域名配置："><a href="#小程序合法域名配置：" class="headerlink" title="小程序合法域名配置："></a>小程序合法域名配置：</h5></li>
</ul>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20230803210743470.png" alt="image-20230803210743470"></p>
<h4 id="全局封装request"><a href="#全局封装request" class="headerlink" title="全局封装request"></a>全局封装request</h4><ul>
<li>安装 axios：</li>
</ul>
<figure class="highlight cmake"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs cmake">npm <span class="hljs-keyword">install</span> axios<br></code></pre></td></tr></table></figure>

<ul>
<li>app.js 下做如下配置：</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><code class="hljs js"><span class="hljs-title class_">App</span>(&#123;<br>  <span class="hljs-title function_">request</span>(<span class="hljs-params">options</span>) &#123;<br>    <span class="hljs-keyword">const</span> &#123; url, method, data, success, fail &#125; = options;<br>    wx.<span class="hljs-title function_">request</span>(&#123;<br>      url,<br>      method,<br>      data,<br>      <span class="hljs-title function_">success</span>(<span class="hljs-params">res</span>) &#123;<br>        success &amp;&amp; <span class="hljs-title function_">success</span>(res.<span class="hljs-property">data</span>);<br>      &#125;,<br>      <span class="hljs-title function_">fail</span>(<span class="hljs-params">error</span>) &#123;<br>        fail &amp;&amp; <span class="hljs-title function_">fail</span>(error);<br>      &#125;<br>    &#125;);<br>  &#125;,<br>  <span class="hljs-attr">onLaunch</span>: <span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) &#123;<br>    <span class="hljs-comment">// 小程序启动时触发，可以进行一些初始化操作</span><br>    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">&quot;App launched&quot;</span>);<br>  &#125;,<br>  <span class="hljs-attr">onShow</span>: <span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) &#123;<br>    <span class="hljs-comment">// 小程序进入前台时触发</span><br>    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">&quot;App showed&quot;</span>);<br>  &#125;,<br>  <span class="hljs-attr">onHide</span>: <span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) &#123;<br>    <span class="hljs-comment">// 小程序进入后台时触发</span><br>    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">&quot;App hided&quot;</span>);<br>  &#125;,<br>  <span class="hljs-attr">globalData</span>: &#123;<br>    <span class="hljs-attr">userInfo</span>: <span class="hljs-literal">null</span>, <span class="hljs-comment">// 全局用户信息</span><br>    <span class="hljs-attr">themeColor</span>: <span class="hljs-string">&#x27;#F44336&#x27;</span>, <span class="hljs-comment">// 全局主题颜色</span><br>  &#125;,<br>&#125;);<br></code></pre></td></tr></table></figure>

<ul>
<li><h5 id="index-js-下如此请求："><a href="#index-js-下如此请求：" class="headerlink" title="index.js 下如此请求："></a>index.js 下如此请求：</h5></li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs js"><span class="hljs-keyword">const</span> app = <span class="hljs-title function_">getApp</span>();<br></code></pre></td></tr></table></figure>

<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><code class="hljs js">app.<span class="hljs-title function_">request</span>(&#123;<br>      <span class="hljs-attr">url</span>: <span class="hljs-string">&#x27;http://localhost:8084/api/user/current&#x27;</span>,<br>      <span class="hljs-attr">method</span>: <span class="hljs-string">&#x27;GET&#x27;</span>,<br>      <span class="hljs-attr">success</span>: <span class="hljs-keyword">function</span> (<span class="hljs-params">data</span>) &#123;<br>        <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(data);<br>      &#125;,<br>      <span class="hljs-attr">fail</span>: <span class="hljs-keyword">function</span> (<span class="hljs-params">error</span>) &#123;<br>        <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(error);<br>      &#125;<br>    &#125;)<br></code></pre></td></tr></table></figure>

<ul>
<li><h5 id="我这里后端接收请求出现如下错误："><a href="#我这里后端接收请求出现如下错误：" class="headerlink" title="我这里后端接收请求出现如下错误："></a>我这里后端接收请求出现如下错误：</h5></li>
</ul>
<figure class="highlight oxygene"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs oxygene">Invalid character found <span class="hljs-keyword">in</span> <span class="hljs-keyword">method</span> <span class="hljs-title function_">name</span> [0<span class="hljs-title function_">x160x030x010x020x000x010x000x010xfc0x030x031E0xe3</span>]0<span class="hljs-title function_">x8eQ0xd60x0e0xf7mJ0x950x920x810xe00x0c0x820xb5</span>)0<span class="hljs-title function_">xc70xdf0xefY0xe30xb8</span>|0<span class="hljs-title function_">x9d0xd430xe50x8f5</span> ]. <span class="hljs-title function_">HTTP</span> <span class="hljs-title function_">method</span> <span class="hljs-title function_">names</span> <span class="hljs-title function_">must</span> <span class="hljs-title function_">be</span> <span class="hljs-title function_">tokens</span><br></code></pre></td></tr></table></figure>

<ul>
<li><h5 id="经排查，是因为把-http-写成-https-了："><a href="#经排查，是因为把-http-写成-https-了：" class="headerlink" title="经排查，是因为把 http 写成 https 了："></a>经排查，是因为把 http 写成 https 了：</h5></li>
</ul>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20230803194528518.png" alt="image-20230803194528518"></p>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20230803194648359.png" alt="image-20230803194648359"></p>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20230803194709864.png" alt="image-20230803194709864"></p>
<h4 id="数据双向绑定"><a href="#数据双向绑定" class="headerlink" title="数据双向绑定"></a>数据双向绑定</h4><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">van-cell-group</span>&gt;</span><br>       <span class="hljs-tag">&lt;<span class="hljs-name">van-field</span> <span class="hljs-attr">required</span> <span class="hljs-attr">model:value</span>=<span class="hljs-string">&quot;&#123;&#123;username&#125;&#125;&quot;</span> <span class="hljs-attr">label</span>=<span class="hljs-string">&quot;昵称&quot;</span> <span class="hljs-attr">placeholder</span>=<span class="hljs-string">&quot;请输入昵称&quot;</span> /&gt;</span><br>       <span class="hljs-tag">&lt;<span class="hljs-name">van-field</span> <span class="hljs-attr">required</span> <span class="hljs-attr">model:value</span>=<span class="hljs-string">&quot;&#123;&#123;phone&#125;&#125;&quot;</span> <span class="hljs-attr">label</span>=<span class="hljs-string">&quot;密码&quot;</span> <span class="hljs-attr">placeholder</span>=<span class="hljs-string">&quot;请设置密码&quot;</span> /&gt;</span><br>       <span class="hljs-tag">&lt;<span class="hljs-name">van-field</span> <span class="hljs-attr">required</span> <span class="hljs-attr">model:value</span>=<span class="hljs-string">&quot;&#123;&#123;password&#125;&#125;&quot;</span> <span class="hljs-attr">label</span>=<span class="hljs-string">&quot;手机号&quot;</span> <span class="hljs-attr">placeholder</span>=<span class="hljs-string">&quot;请输入手机号&quot;</span> /&gt;</span><br>     <span class="hljs-tag">&lt;/<span class="hljs-name">van-cell-group</span>&gt;</span><br></code></pre></td></tr></table></figure>

<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs js"><span class="hljs-attr">data</span>: &#123;<br>  <span class="hljs-attr">username</span>: <span class="hljs-string">&#x27;&#x27;</span>,<br>  <span class="hljs-attr">password</span>: <span class="hljs-string">&#x27;&#x27;</span>,<br>  <span class="hljs-attr">phone</span>: <span class="hljs-string">&#x27;&#x27;</span><br>&#125;,<br></code></pre></td></tr></table></figure>

<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><code class="hljs js"><span class="hljs-title function_">goToRegister</span>(<span class="hljs-params"></span>) &#123;<br>    app.<span class="hljs-title function_">request</span>(&#123;<br>      <span class="hljs-attr">url</span>: <span class="hljs-string">&#x27;http://localhost:8084/api/user/register&#x27;</span>,<br>      <span class="hljs-attr">method</span>: <span class="hljs-string">&#x27;POST&#x27;</span>,<br>      <span class="hljs-attr">data</span>: &#123;<br>        <span class="hljs-attr">username</span>: <span class="hljs-variable language_">this</span>.<span class="hljs-property">data</span>.<span class="hljs-property">username</span>,<br>        <span class="hljs-attr">password</span>: <span class="hljs-variable language_">this</span>.<span class="hljs-property">data</span>.<span class="hljs-property">password</span>,<br>        <span class="hljs-attr">phone</span>: <span class="hljs-variable language_">this</span>.<span class="hljs-property">data</span>.<span class="hljs-property">phone</span><br>      &#125;,<br>      <span class="hljs-attr">success</span>: <span class="hljs-keyword">function</span> (<span class="hljs-params">data</span>) &#123;<br>        <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(data);<br>      &#125;,<br>      <span class="hljs-attr">fail</span>: <span class="hljs-keyword">function</span> (<span class="hljs-params">error</span>) &#123;<br>        <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(error);<br>      &#125;<br>    &#125;)<br>  &#125;,<br></code></pre></td></tr></table></figure>

<ul>
<li><h5 id="参考：微信小程序双向数据绑定-小程序双向绑定-锅盖哒的博客-CSDN博客"><a href="#参考：微信小程序双向数据绑定-小程序双向绑定-锅盖哒的博客-CSDN博客" class="headerlink" title="参考：微信小程序双向数据绑定_小程序双向绑定_锅盖哒的博客-CSDN博客"></a>参考：<a target="_blank" rel="noopener" href="https://blog.csdn.net/A12536365214/article/details/131320188">微信小程序双向数据绑定_小程序双向绑定_锅盖哒的博客-CSDN博客</a></h5></li>
<li><h5 id="即可实现简单的双向数据绑定（2023-08-04早）"><a href="#即可实现简单的双向数据绑定（2023-08-04早）" class="headerlink" title="即可实现简单的双向数据绑定（2023/08/04早）"></a>即可实现简单的双向数据绑定（2023/08/04早）</h5></li>
</ul>
<h4 id="生命周期函数"><a href="#生命周期函数" class="headerlink" title="生命周期函数"></a>生命周期函数</h4><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs js"><span class="hljs-comment">/**</span><br><span class="hljs-comment">   * 生命周期函数--监听页面加载</span><br><span class="hljs-comment">   */</span><br>  <span class="hljs-title function_">onLoad</span>(<span class="hljs-params">options</span>) &#123;<br><br>  &#125;,<br></code></pre></td></tr></table></figure>

<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs js"><span class="hljs-comment">/**</span><br><span class="hljs-comment">  * 生命周期函数--监听页面显示</span><br><span class="hljs-comment">  */</span><br> <span class="hljs-title function_">onShow</span>(<span class="hljs-params"></span>) &#123;<br>   <span class="hljs-title class_">Toast</span>(<span class="hljs-string">&quot;分类~&quot;</span>)<br> &#125;,<br></code></pre></td></tr></table></figure>

<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs js"><span class="hljs-comment">/**</span><br><span class="hljs-comment"> * 生命周期函数--监听页面隐藏</span><br><span class="hljs-comment"> */</span><br><span class="hljs-title function_">onHide</span>(<span class="hljs-params"></span>) &#123;<br><br>&#125;,<br></code></pre></td></tr></table></figure>

<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs js"><span class="hljs-comment">/**</span><br><span class="hljs-comment"> * 生命周期函数--监听页面卸载</span><br><span class="hljs-comment"> */</span><br><span class="hljs-title function_">onUnload</span>(<span class="hljs-params"></span>) &#123;<br><br>&#125;,<br></code></pre></td></tr></table></figure>

<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs js"><span class="hljs-comment">/**</span><br><span class="hljs-comment"> * 生命周期函数--监听页面初次渲染完成</span><br><span class="hljs-comment"> */</span><br><span class="hljs-title function_">onReady</span>(<span class="hljs-params"></span>) &#123;<br><br>&#125;,<br></code></pre></td></tr></table></figure>

<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><code class="hljs js"><br><span class="hljs-comment">/**</span><br><span class="hljs-comment"> * 页面相关事件处理函数--监听用户下拉动作</span><br><span class="hljs-comment"> */</span><br><span class="hljs-title function_">onPullDownRefresh</span>(<span class="hljs-params"></span>) &#123;<br><br>&#125;,<br><br><span class="hljs-comment">/**</span><br><span class="hljs-comment"> * 页面上拉触底事件的处理函数</span><br><span class="hljs-comment"> */</span><br><span class="hljs-title function_">onReachBottom</span>(<span class="hljs-params"></span>) &#123;<br><br>&#125;,<br><br><span class="hljs-comment">/**</span><br><span class="hljs-comment"> * 用户点击右上角分享</span><br><span class="hljs-comment"> */</span><br><span class="hljs-title function_">onShareAppMessage</span>(<span class="hljs-params"></span>) &#123;<br><br>&#125;<br></code></pre></td></tr></table></figure>

<h4 id="路由跳转"><a href="#路由跳转" class="headerlink" title="路由跳转"></a>路由跳转</h4><ul>
<li><h5 id="官方提供的路由跳转有以下5种："><a href="#官方提供的路由跳转有以下5种：" class="headerlink" title="官方提供的路由跳转有以下5种："></a>官方提供的路由跳转有以下5种：</h5></li>
</ul>
<figure class="highlight mipsasm"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs mipsasm">wx.<span class="hljs-keyword">switchTab	</span>跳转到 tabBar 页面，并关闭其他所有非 tabBar 页面<br></code></pre></td></tr></table></figure>

<figure class="highlight stylus"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs stylus">wx<span class="hljs-selector-class">.reLaunch</span>		关闭所有页面，打开到应用内的某个页面<br></code></pre></td></tr></table></figure>

<figure class="highlight stylus"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs stylus">wx<span class="hljs-selector-class">.redirectTo</span>	关闭当前页面，跳转到应用内的某个页面。但是不允许跳转到 tabbar 页面<br></code></pre></td></tr></table></figure>

<figure class="highlight stylus"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs stylus">wx<span class="hljs-selector-class">.navigateTo</span>	保留当前页面，跳转到应用内的某个页面。但是不能跳到 tabbar 页面<br></code></pre></td></tr></table></figure>

<figure class="highlight stylus"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs stylus">wx<span class="hljs-selector-class">.navigateBack</span>	关闭当前页面，返回上一页面或多级页面<br></code></pre></td></tr></table></figure>

<ul>
<li><h5 id="我们可以分析出在不同的业务场景下，使用怎样的路由跳转更合适："><a href="#我们可以分析出在不同的业务场景下，使用怎样的路由跳转更合适：" class="headerlink" title="我们可以分析出在不同的业务场景下，使用怎样的路由跳转更合适："></a>我们可以分析出在不同的业务场景下，使用怎样的路由跳转更合适：</h5></li>
<li><h5 id="wx-switchTab：支持跳转至tabbar页面"><a href="#wx-switchTab：支持跳转至tabbar页面" class="headerlink" title="wx.switchTab：支持跳转至tabbar页面"></a>wx.switchTab：支持跳转至tabbar页面</h5><ul>
<li>跳转至tabbar页，关闭其他所有非 tabBar 页面</li>
</ul>
</li>
<li><h5 id="wx-redirectTo、wx-navigateTo：支持跳转至非tabbar页面"><a href="#wx-redirectTo、wx-navigateTo：支持跳转至非tabbar页面" class="headerlink" title="wx.redirectTo、wx.navigateTo：支持跳转至非tabbar页面"></a>wx.redirectTo、wx.navigateTo：支持跳转至非tabbar页面</h5><ul>
<li>前者关闭当前页面，后者保留当前页面</li>
<li>wx.navigateBack：与wx.navigateTo配合，返回上一级页面</li>
</ul>
</li>
<li><h5 id="wx-reLaunch：支持跳转至任何页面"><a href="#wx-reLaunch：支持跳转至任何页面" class="headerlink" title="wx.reLaunch：支持跳转至任何页面"></a>wx.reLaunch：支持跳转至任何页面</h5><ul>
<li>关闭所有页面，打开到应用内的某个页面</li>
</ul>
</li>
<li><h5 id="那么从登录页跳转至个人页，就应该用wx-switchTab-wx-reLaunch（2023-08-05早）"><a href="#那么从登录页跳转至个人页，就应该用wx-switchTab-wx-reLaunch（2023-08-05早）" class="headerlink" title="那么从登录页跳转至个人页，就应该用wx.switchTab / wx.reLaunch（2023/08/05早）"></a>那么从登录页跳转至个人页，就应该用wx.switchTab / wx.reLaunch（2023/08/05早）</h5></li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><code class="hljs js"><span class="hljs-title function_">goToLogin</span>(<span class="hljs-params"></span>) &#123;<br>   app.<span class="hljs-title function_">request</span>(&#123;<br>     <span class="hljs-attr">url</span>: <span class="hljs-string">&#x27;http://localhost:8084/api/user/login&#x27;</span>,<br>     <span class="hljs-attr">method</span>: <span class="hljs-string">&#x27;POST&#x27;</span>,<br>     <span class="hljs-attr">data</span>: &#123;<br>       <span class="hljs-attr">username</span>: <span class="hljs-variable language_">this</span>.<span class="hljs-property">data</span>.<span class="hljs-property">username</span>,<br>       <span class="hljs-attr">password</span>: <span class="hljs-variable language_">this</span>.<span class="hljs-property">data</span>.<span class="hljs-property">password</span>,<br>     &#125;,<br>     <span class="hljs-attr">success</span>: <span class="hljs-keyword">function</span> (<span class="hljs-params">res</span>) &#123;<br>       <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(res)<br>       <span class="hljs-keyword">const</span> data = res.<span class="hljs-property">data</span>;<br><br>       <span class="hljs-keyword">if</span> (data.<span class="hljs-property">code</span> == <span class="hljs-number">0</span>) &#123;<br>         <span class="hljs-comment">// 设置sessionID到缓存</span><br>         wx.<span class="hljs-title function_">setStorageSync</span>(<span class="hljs-string">&#x27;sessionID&#x27;</span>, res.<span class="hljs-property">header</span>[<span class="hljs-string">&quot;Set-Cookie&quot;</span>]);<br>         <span class="hljs-title class_">Notify</span>(&#123; <span class="hljs-attr">type</span>: <span class="hljs-string">&#x27;success&#x27;</span>, <span class="hljs-attr">message</span>: data.<span class="hljs-property">description</span> &#125;);<br>         wx.<span class="hljs-title function_">reLaunch</span>(&#123;<br>           <span class="hljs-attr">url</span>: <span class="hljs-string">&#x27;/pages/user/index&#x27;</span><br>         &#125;)<br>       &#125; <span class="hljs-keyword">else</span> &#123;<br>         <span class="hljs-title class_">Notify</span>(&#123; <span class="hljs-attr">type</span>: <span class="hljs-string">&#x27;warning&#x27;</span>, <span class="hljs-attr">message</span>: data.<span class="hljs-property">description</span> &#125;);<br>       &#125;<br>     &#125;,<br>     <span class="hljs-attr">fail</span>: <span class="hljs-keyword">function</span> (<span class="hljs-params">error</span>) &#123;<br>       <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(error);<br>     &#125;<br>   &#125;)<br> &#125;,<br></code></pre></td></tr></table></figure>

<h4 id="data已初始化，未触发数据绑定"><a href="#data已初始化，未触发数据绑定" class="headerlink" title="data已初始化，未触发数据绑定"></a>data已初始化，未触发数据绑定</h4><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs js"><span class="hljs-title class_">Page</span>(&#123;<br>  <span class="hljs-attr">data</span>: &#123;<br>    <span class="hljs-attr">imgs</span>: [],<br>    <span class="hljs-attr">urlList</span>: []<br>  &#125;,<br></code></pre></td></tr></table></figure>

<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><code class="hljs js"> <span class="hljs-comment">// 页面创建时执行</span><br>  <span class="hljs-title function_">onShow</span>(<span class="hljs-params"></span>) &#123;<br>    <span class="hljs-title class_">Toast</span>(<span class="hljs-string">&quot;惊喜多多~&quot;</span>)<br>    <span class="hljs-keyword">var</span> _this = <span class="hljs-variable language_">this</span><br>    <span class="hljs-comment">// 获取壁纸</span><br>    app.<span class="hljs-title function_">request</span>(&#123;<br>      <span class="hljs-attr">url</span>: <span class="hljs-string">&#x27;http://localhost:8084/api/wallpaper/listPage&#x27;</span>,<br>      <span class="hljs-attr">method</span>: <span class="hljs-string">&#x27;GET&#x27;</span>,<br>      <span class="hljs-attr">success</span>: <span class="hljs-keyword">function</span> (<span class="hljs-params">res</span>) &#123;<br>        <span class="hljs-keyword">const</span> data = res.<span class="hljs-property">data</span>;<br>      <span class="hljs-comment">// 拿取到imgs列表</span><br>        _this.<span class="hljs-title function_">setData</span>(&#123;<br>          <span class="hljs-string">&#x27;imgs&#x27;</span>: data.<span class="hljs-property">data</span>.<span class="hljs-property">records</span><br>        &#125;);<br><span class="hljs-comment">// 拿取到urlList列表</span><br>        _this.<span class="hljs-property">data</span>.<span class="hljs-property">imgs</span>.<span class="hljs-title function_">forEach</span>(<span class="hljs-function">(<span class="hljs-params">item</span>) =&gt;</span> &#123;<br>          _this.<span class="hljs-property">data</span>.<span class="hljs-property">urlList</span>.<span class="hljs-title function_">push</span>(item.<span class="hljs-property">wallpaperUrl</span>); <br>        &#125;);<br>      &#125;,<br><br>      <span class="hljs-attr">fail</span>: <span class="hljs-keyword">function</span> (<span class="hljs-params">error</span>) &#123;<br>        <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(error);<br>      &#125;<br>    &#125;)<br>  &#125;,<br></code></pre></td></tr></table></figure>

<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">block</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;image-list&quot;</span> <span class="hljs-attr">wx:for</span>=<span class="hljs-string">&quot;&#123;&#123;urlList&#125;&#125;&quot;</span> <span class="hljs-attr">wx:key</span>=<span class="hljs-string">&quot;index&quot;</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">image</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;img&quot;</span> <span class="hljs-attr">src</span>=<span class="hljs-string">&quot;&#123;&#123;item&#125;&#125;&quot;</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">&quot;刚刚&quot;</span> <span class="hljs-attr">mode</span>=<span class="hljs-string">&quot;widthFix&quot;</span> /&gt;</span><br>          <span class="hljs-tag">&lt;/<span class="hljs-name">block</span>&gt;</span><br></code></pre></td></tr></table></figure>

<ul>
<li><h5 id="这里的-image-标签，仍旧无法正常绑定到urlList"><a href="#这里的-image-标签，仍旧无法正常绑定到urlList" class="headerlink" title="这里的 image 标签，仍旧无法正常绑定到urlList"></a>这里的 image 标签，仍旧无法正常绑定到urlList</h5></li>
</ul>
<ul>
<li><h5 id="当show-生命周期函数未执行完毕，即urlList仍为空数组时，data在页面展示时已经初始化"><a href="#当show-生命周期函数未执行完毕，即urlList仍为空数组时，data在页面展示时已经初始化" class="headerlink" title="当show()生命周期函数未执行完毕，即urlList仍为空数组时，data在页面展示时已经初始化"></a>当show()生命周期函数未执行完毕，即urlList仍为空数组时，data在页面展示时已经初始化</h5></li>
</ul>
<ul>
<li><h5 id="如此改造show-生命周期函数："><a href="#如此改造show-生命周期函数：" class="headerlink" title="如此改造show()生命周期函数："></a>如此改造show()生命周期函数：</h5></li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><code class="hljs js"><span class="hljs-comment">// 页面创建时执行</span><br><span class="hljs-title function_">onShow</span>(<span class="hljs-params"></span>) &#123;<br>  <span class="hljs-title class_">Toast</span>(<span class="hljs-string">&quot;惊喜多多~&quot;</span>)<br>  <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">getData</span>();<br>&#125;,<br><span class="hljs-comment">// 获取imgs列表</span><br><span class="hljs-title function_">getData</span>(<span class="hljs-params"></span>) &#123;<br>  <span class="hljs-keyword">var</span> _this = <span class="hljs-variable language_">this</span>;<br>  <span class="hljs-comment">// 获取壁纸</span><br>  app.<span class="hljs-title function_">request</span>(&#123;<br>    <span class="hljs-attr">url</span>: <span class="hljs-string">&#x27;http://localhost:8084/api/wallpaper/listPage&#x27;</span>,<br>    <span class="hljs-attr">method</span>: <span class="hljs-string">&#x27;GET&#x27;</span>,<br>    <span class="hljs-attr">success</span>: <span class="hljs-keyword">function</span> (<span class="hljs-params">res</span>) &#123;<br>      <span class="hljs-keyword">const</span> data = res.<span class="hljs-property">data</span>;<br>      _this.<span class="hljs-title function_">setData</span>(&#123;<br>        <span class="hljs-string">&#x27;imgs&#x27;</span>: data.<span class="hljs-property">data</span>.<span class="hljs-property">records</span><br>      &#125;);<br>      _this.<span class="hljs-title function_">setUrlList</span>();<br>    &#125;<br>  &#125;);<br>&#125;,<br><span class="hljs-comment">// 获取url列表</span><br><span class="hljs-title function_">setUrlList</span>(<span class="hljs-params"></span>) &#123;<br>  <span class="hljs-keyword">var</span> urlList = [];<br>  <span class="hljs-variable language_">this</span>.<span class="hljs-property">data</span>.<span class="hljs-property">imgs</span>.<span class="hljs-title function_">forEach</span>(<span class="hljs-function">(<span class="hljs-params">item</span>) =&gt;</span> &#123;<br>    urlList.<span class="hljs-title function_">push</span>(item.<span class="hljs-property">wallpaperUrl</span>);<br>  &#125;);<br>  <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">setData</span>(&#123;<br>    <span class="hljs-string">&#x27;urlList&#x27;</span>: urlList<br>  &#125;);<br>&#125;,<br></code></pre></td></tr></table></figure>

<ul>
<li><h5 id="成功解决urlList数据双向绑定问题（2023-08-05早）"><a href="#成功解决urlList数据双向绑定问题（2023-08-05早）" class="headerlink" title="成功解决urlList数据双向绑定问题（2023/08/05早）"></a>成功解决urlList数据双向绑定问题（2023/08/05早）</h5></li>
</ul>
<h4 id="无法获取Session"><a href="#无法获取Session" class="headerlink" title="无法获取Session"></a>无法获取Session</h4><ul>
<li><p><a target="_blank" rel="noopener" href="https://pythonjishu.com/kgaxhpjbuoqadde/">微信小程序后端无法保持session的原因及解决办法问题 - Python技术站 (pythonjishu.com)</a></p>
</li>
<li><h5 id="这种方法是不好使的："><a href="#这种方法是不好使的：" class="headerlink" title="这种方法是不好使的："></a>这种方法是不好使的：</h5></li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><code class="hljs js"><span class="hljs-comment">// 注册</span><br> <span class="hljs-title function_">goToLogin</span>(<span class="hljs-params"></span>) &#123;<br>   app.<span class="hljs-title function_">request</span>(&#123;<br>     <span class="hljs-attr">url</span>: <span class="hljs-string">&#x27;http://localhost:8084/api/user/login&#x27;</span>,<br>     <span class="hljs-attr">method</span>: <span class="hljs-string">&#x27;POST&#x27;</span>,<br>     <span class="hljs-attr">data</span>: &#123;<br>       <span class="hljs-attr">username</span>: <span class="hljs-variable language_">this</span>.<span class="hljs-property">data</span>.<span class="hljs-property">username</span>,<br>       <span class="hljs-attr">password</span>: <span class="hljs-variable language_">this</span>.<span class="hljs-property">data</span>.<span class="hljs-property">password</span>,<br>     &#125;,<br>     <span class="hljs-attr">success</span>: <span class="hljs-keyword">function</span> (<span class="hljs-params">res</span>) &#123;<br>       <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(res)<br>       <span class="hljs-keyword">const</span> data = res.<span class="hljs-property">data</span>;<br><br>       <span class="hljs-keyword">if</span> (data.<span class="hljs-property">code</span> == <span class="hljs-number">0</span>) &#123;<br>         <span class="hljs-comment">// 设置sessionID到缓存</span><br>         wx.<span class="hljs-title function_">setStorageSync</span>(<span class="hljs-string">&#x27;sessionID&#x27;</span>, res.<span class="hljs-property">header</span>[<span class="hljs-string">&quot;Set-Cookie&quot;</span>]);<br>         <span class="hljs-title class_">Notify</span>(&#123; <span class="hljs-attr">type</span>: <span class="hljs-string">&#x27;success&#x27;</span>, <span class="hljs-attr">message</span>: data.<span class="hljs-property">description</span> &#125;);<br>         wx.<span class="hljs-title function_">reLaunch</span>(&#123;<br>           <span class="hljs-attr">url</span>: <span class="hljs-string">&#x27;/pages/user/index&#x27;</span><br>         &#125;)<br>       &#125; <span class="hljs-keyword">else</span> &#123;<br>         <span class="hljs-title class_">Notify</span>(&#123; <span class="hljs-attr">type</span>: <span class="hljs-string">&#x27;warning&#x27;</span>, <span class="hljs-attr">message</span>: data.<span class="hljs-property">description</span> &#125;);<br>       &#125;<br>     &#125;,<br>     <span class="hljs-attr">fail</span>: <span class="hljs-keyword">function</span> (<span class="hljs-params">error</span>) &#123;<br>       <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(error);<br>     &#125;<br>   &#125;)<br> &#125;,<br></code></pre></td></tr></table></figure>

<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><code class="hljs js">app.<span class="hljs-title function_">request</span>(&#123;<br>      <span class="hljs-attr">url</span>: <span class="hljs-string">&#x27;http://localhost:8084/api/user/current&#x27;</span>,<br>      <span class="hljs-attr">method</span>: <span class="hljs-string">&#x27;GET&#x27;</span>,<br>      <span class="hljs-attr">header</span>: &#123;<br>        <span class="hljs-string">&#x27;Content-Type&#x27;</span>: <span class="hljs-string">&#x27;application/json&#x27;</span>,<br>        <span class="hljs-string">&#x27;sessionID&#x27;</span>: wx.<span class="hljs-title function_">getStorageSync</span>(<span class="hljs-string">&#x27;sessionID&#x27;</span>)<br>      &#125;,<br>      <span class="hljs-attr">success</span>: <span class="hljs-keyword">function</span> (<span class="hljs-params">data</span>) &#123;<br>        <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(data);<br>      &#125;,<br>      <span class="hljs-attr">fail</span>: <span class="hljs-keyword">function</span> (<span class="hljs-params">error</span>) &#123;<br>        <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(error);<br>      &#125;<br>    &#125;)<br>  &#125;,<br></code></pre></td></tr></table></figure>

<h4 id="小程序登录-用户身份标识"><a href="#小程序登录-用户身份标识" class="headerlink" title="小程序登录 - 用户身份标识"></a>小程序登录 - 用户身份标识</h4><ul>
<li><h5 id="这里讲一下在微信小程序开发过程中，如何做到记录用户登录态，标识用户身份（2023-08-06早）"><a href="#这里讲一下在微信小程序开发过程中，如何做到记录用户登录态，标识用户身份（2023-08-06早）" class="headerlink" title="这里讲一下在微信小程序开发过程中，如何做到记录用户登录态，标识用户身份（2023/08/06早）"></a>这里讲一下在微信小程序开发过程中，如何做到记录用户登录态，标识用户身份（2023/08/06早）</h5></li>
<li><p><a target="_blank" rel="noopener" href="https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/user-login/code2Session.html">小程序登录 / 小程序登录 | 小程序登录 | 微信开放文档 (qq.com)</a></p>
</li>
<li><p><a target="_blank" rel="noopener" href="https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/login.html">开放能力 / 用户信息 / 小程序登录 | 小程序登录 | 微信开放文档 (qq.com)</a></p>
</li>
<li><p><a target="_blank" rel="noopener" href="https://www.hutool.cn/docs/#/http/Http%E5%AE%A2%E6%88%B7%E7%AB%AF%E5%B7%A5%E5%85%B7%E7%B1%BB-HttpUtil">Http客户端工具类-HttpUtil (hutool.cn)</a></p>
</li>
<li><h5 id="整个流程如下："><a href="#整个流程如下：" class="headerlink" title="整个流程如下："></a>整个流程如下：</h5><ul>
<li><p>前台获取临时登录凭证code</p>
</li>
<li><p>发送code到服务端</p>
</li>
<li><p>服务端拿到code，通过code调用Code3Session接口，获取openid、session_key</p>
</li>
<li><p>服务端返回openid、session_key到前台</p>
</li>
<li><p>前台拿到openid、session_key，作为token</p>
</li>
<li><p>之后，前台发送请求，携带token</p>
</li>
<li><p>服务器通过校验token，选择是否响应该请求</p>
</li>
</ul>
</li>
<li><h5 id="前台发送code到服务端："><a href="#前台发送code到服务端：" class="headerlink" title="前台发送code到服务端："></a>前台发送code到服务端：</h5></li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><code class="hljs js"><span class="hljs-comment">// 登录</span><br>  <span class="hljs-title function_">goToLogin</span>(<span class="hljs-params"></span>) &#123;<br>    <span class="hljs-keyword">var</span> _this = <span class="hljs-variable language_">this</span>;<br>    wx.<span class="hljs-title function_">login</span>(&#123;<br>      <span class="hljs-title function_">success</span>(<span class="hljs-params">res</span>) &#123;<br>        <span class="hljs-keyword">if</span> (res.<span class="hljs-property">code</span>) &#123;<br>          <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">&quot;code = &quot;</span> + res.<span class="hljs-property">code</span>)<br>          <span class="hljs-comment">//发起网络请求</span><br>          wx.<span class="hljs-title function_">request</span>(&#123;<br>            <span class="hljs-attr">url</span>: <span class="hljs-string">&#x27;http://localhost:8084/api/user/login&#x27;</span>,<br>            <span class="hljs-attr">method</span>: <span class="hljs-string">&#x27;POST&#x27;</span>,<br>            <span class="hljs-attr">data</span>: &#123;<br>              <span class="hljs-attr">code</span>: res.<span class="hljs-property">code</span>,<br>              <span class="hljs-attr">username</span>: _this.<span class="hljs-property">data</span>.<span class="hljs-property">username</span>,<br>              <span class="hljs-attr">password</span>: _this.<span class="hljs-property">data</span>.<span class="hljs-property">password</span>,<br>            &#125;,<br>            <span class="hljs-attr">success</span>: <span class="hljs-keyword">function</span> (<span class="hljs-params">res</span>) &#123;<br>              <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(res)<br>              <span class="hljs-keyword">const</span> data = res.<span class="hljs-property">data</span>;<br><br>              <span class="hljs-keyword">if</span> (data.<span class="hljs-property">code</span> == <span class="hljs-number">0</span>) &#123;<br>                <span class="hljs-comment">// 设置sessionID到缓存</span><br>                <span class="hljs-title class_">Notify</span>(&#123; <span class="hljs-attr">type</span>: <span class="hljs-string">&#x27;success&#x27;</span>, <span class="hljs-attr">message</span>: data.<span class="hljs-property">description</span> &#125;);<br>                wx.<span class="hljs-title function_">reLaunch</span>(&#123;<br>                  <span class="hljs-attr">url</span>: <span class="hljs-string">&#x27;/pages/user/index&#x27;</span><br>                &#125;)<br>              &#125; <span class="hljs-keyword">else</span> &#123;<br>                <span class="hljs-title class_">Notify</span>(&#123; <span class="hljs-attr">type</span>: <span class="hljs-string">&#x27;warning&#x27;</span>, <span class="hljs-attr">message</span>: data.<span class="hljs-property">description</span> &#125;);<br>              &#125;<br>            &#125;,<br>            <span class="hljs-attr">fail</span>: <span class="hljs-keyword">function</span> (<span class="hljs-params">error</span>) &#123;<br>              <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(error);<br>            &#125;<br>          &#125;)<br>        &#125; <span class="hljs-keyword">else</span> &#123;<br>          <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">&#x27;登录失败！&#x27;</span> + res.<span class="hljs-property">errMsg</span>)<br>        &#125;<br>      &#125;<br>    &#125;)<br>  &#125;,<br></code></pre></td></tr></table></figure>

<ul>
<li><h5 id="后台："><a href="#后台：" class="headerlink" title="后台："></a>后台：</h5></li>
<li><p>服务端拿到code，通过code调用Code3Session接口，获取openid、session_key</p>
</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">private</span> <span class="hljs-keyword">final</span> <span class="hljs-type">String</span> <span class="hljs-variable">appId</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;wxd12f7c79bd639a9b&quot;</span>;<br> <span class="hljs-keyword">private</span> <span class="hljs-keyword">final</span> <span class="hljs-type">String</span> <span class="hljs-variable">secret</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;8a99ccc1802486c1387c1cda45288dd5&quot;</span>;<br></code></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><code class="hljs java"> <span class="hljs-keyword">public</span> String <span class="hljs-title function_">getCode2Session</span><span class="hljs-params">(String appId, String secret, String code)</span> &#123;<br>     <span class="hljs-type">String</span> <span class="hljs-variable">url</span> <span class="hljs-operator">=</span> String.format(<span class="hljs-string">&quot;https://api.weixin.qq.com/sns/jscode2session?appid=%s&amp;secret=%s&amp;js_code=%s&amp;grant_type=authorization_code&quot;</span>, appId, secret, code);<br><br>     <span class="hljs-type">HttpRequest</span> <span class="hljs-variable">request</span> <span class="hljs-operator">=</span> HttpRequest.get(url);<br>     log.info(<span class="hljs-string">&quot;result = &quot;</span> + request.execute());<br>     <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;request&quot;</span>;<br> &#125;<br> <br> <span class="hljs-comment">/** 后台也可以这样写 **/</span><br><br><span class="hljs-type">String</span> <span class="hljs-variable">url</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;https://api.weixin.qq.com/sns/jscode2session&quot;</span>;<br>     HashMap&lt;String, Object&gt; paramMap = <span class="hljs-keyword">new</span> <span class="hljs-title class_">HashMap</span>&lt;&gt;();<br>     paramMap.put(<span class="hljs-string">&quot;appid&quot;</span>, appId);<br>     paramMap.put(<span class="hljs-string">&quot;secret&quot;</span>, secret);<br>     paramMap.put(<span class="hljs-string">&quot;js_code&quot;</span>, code);<br>     paramMap.put(<span class="hljs-string">&quot;grant_type&quot;</span>, <span class="hljs-string">&quot;authorization_code&quot;</span>);<br>     <span class="hljs-type">String</span> <span class="hljs-variable">result</span> <span class="hljs-operator">=</span> HttpUtil.get(url, paramMap);<br>     log.info(<span class="hljs-string">&quot;result = &quot;</span> + result);<br>     <span class="hljs-keyword">return</span> result;<br></code></pre></td></tr></table></figure>

<ul>
<li><h5 id="成功："><a href="#成功：" class="headerlink" title="成功："></a>成功：</h5></li>
</ul>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs css">Response <span class="hljs-selector-tag">Body</span>: <br>    &#123;&quot;session_key&quot;:<span class="hljs-string">&quot;oZ0ju27QocpPhHF2Z1MrtQ==&quot;</span>,<span class="hljs-string">&quot;openid&quot;</span>:<span class="hljs-string">&quot;otcWC6_yPHlB2Q6e0vIrB_J2iYHs&quot;</span>&#125;<br></code></pre></td></tr></table></figure>

<ul>
<li><h5 id="失败"><a href="#失败" class="headerlink" title="失败"></a>失败</h5></li>
</ul>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs json"><span class="hljs-punctuation">&#123;</span><span class="hljs-attr">&quot;errcode&quot;</span><span class="hljs-punctuation">:</span><span class="hljs-number">40029</span><span class="hljs-punctuation">,</span><span class="hljs-attr">&quot;errmsg&quot;</span><span class="hljs-punctuation">:</span><span class="hljs-string">&quot;invalid code, rid: 64cf07f9-36a4c687-09c960f0&quot;</span><span class="hljs-punctuation">&#125;</span><br></code></pre></td></tr></table></figure>

<ul>
<li><p>服务端返回openid、session_key到前台</p>
</li>
<li></li>
<li><p>前台拿到openid、session_key，作为token</p>
</li>
<li><p>之后，前台发送请求，携带token</p>
</li>
<li></li>
<li><p>服务器通过校验token，选择是否响应该请求</p>
</li>
</ul>
<figure class="highlight arcade"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><code class="hljs arcade">onShow () &#123;<br>  Toast(<span class="hljs-string">&#x27;个人中心~&#x27;</span>);<br>  <span class="hljs-built_in">console</span>.<span class="hljs-built_in">log</span>(<span class="hljs-string">&quot;seeesion_key = &quot;</span> + wx.getStorageSync(<span class="hljs-string">&#x27;session_key&#x27;</span>))<br><br>  app.request(&#123;<br>    <span class="hljs-attr">url</span>: <span class="hljs-string">&#x27;http://localhost:8084/api/user/current&#x27;</span>,<br>    <span class="hljs-attr">method</span>: <span class="hljs-string">&#x27;GET&#x27;</span>,<br>    <span class="hljs-attr">header</span>: &#123;<br>      <span class="hljs-string">&#x27;Authorization&#x27;</span>: <span class="hljs-string">&#x27;Bearer &#x27;</span> + wx.getStorageSync(<span class="hljs-string">&#x27;session_key&#x27;</span>)<br>    &#125;,<br>    <span class="hljs-attr">success</span>: <span class="hljs-keyword">function</span> (<span class="hljs-params">data</span>) &#123;<br>      <span class="hljs-built_in">console</span>.<span class="hljs-built_in">log</span>(data);<br>    &#125;,<br>    <span class="hljs-attr">fail</span>: <span class="hljs-keyword">function</span> (<span class="hljs-params">error</span>) &#123;<br>      <span class="hljs-built_in">console</span>.<span class="hljs-built_in">log</span>(error);<br>    &#125;<br>  &#125;)<br>&#125;,<br></code></pre></td></tr></table></figure>

<h4 id="路由跳转、携带参数"><a href="#路由跳转、携带参数" class="headerlink" title="路由跳转、携带参数"></a>路由跳转、携带参数</h4><ul>
<li><h5 id="首页跳转至壁纸详情页，携带url路径："><a href="#首页跳转至壁纸详情页，携带url路径：" class="headerlink" title="首页跳转至壁纸详情页，携带url路径："></a>首页跳转至壁纸详情页，携带url路径：</h5></li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs js"><span class="hljs-comment">// 跳转到壁纸详情页</span><br><span class="hljs-title function_">onClickShow</span>(<span class="hljs-params">e</span>) &#123;<br>  <span class="hljs-keyword">const</span> imageUrl = e.<span class="hljs-property">currentTarget</span>.<span class="hljs-property">dataset</span>.<span class="hljs-property">url</span>;<br>  <span class="hljs-keyword">const</span> parameter = &#123;<br>    <span class="hljs-attr">url</span>: imageUrl<br>  &#125;;<br>  <span class="hljs-keyword">const</span> url = <span class="hljs-string">&#x27;/pages/imageInfo/index?parameter=&#x27;</span> + <span class="hljs-built_in">encodeURIComponent</span>(<span class="hljs-title class_">JSON</span>.<span class="hljs-title function_">stringify</span>(parameter));<br>  wx.<span class="hljs-title function_">navigateTo</span>(&#123;<br>    <span class="hljs-attr">url</span>: url<br>  &#125;);<br>&#125;,<br></code></pre></td></tr></table></figure>

<ul>
<li><h5 id="壁纸详情页接收参数："><a href="#壁纸详情页接收参数：" class="headerlink" title="壁纸详情页接收参数："></a>壁纸详情页接收参数：</h5></li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><code class="hljs js"><span class="hljs-comment">/**</span><br><span class="hljs-comment"> * 生命周期函数--监听页面加载</span><br><span class="hljs-comment"> */</span><br><span class="hljs-title function_">onLoad</span>(<span class="hljs-params">options</span>) &#123;<br>  <span class="hljs-keyword">const</span> &#123;url&#125; = <span class="hljs-title class_">JSON</span>.<span class="hljs-title function_">parse</span>(<span class="hljs-built_in">decodeURIComponent</span>(options.<span class="hljs-property">parameter</span>));<br>  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(url)<br>  <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">getData</span>(url)<br>&#125;,<br><br><span class="hljs-comment">// 获取壁纸url</span><br><span class="hljs-title function_">getData</span>(<span class="hljs-params">url</span>)&#123;<br>  <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">setData</span>(&#123;<br>    <span class="hljs-string">&#x27;url&#x27;</span>: url<br>  &#125;)<br>  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-variable language_">this</span>.<span class="hljs-property">data</span>.<span class="hljs-property">url</span>)<br>&#125;,<br></code></pre></td></tr></table></figure>

<ul>
<li><h5 id="要注意这里的-options-拿到的数据是封装好的对象，要使用如上方式接收参数：（2023-08-09晚）"><a href="#要注意这里的-options-拿到的数据是封装好的对象，要使用如上方式接收参数：（2023-08-09晚）" class="headerlink" title="要注意这里的 options 拿到的数据是封装好的对象，要使用如上方式接收参数：（2023/08/09晚）"></a>要注意这里的 options 拿到的数据是封装好的对象，要使用如上方式接收参数：（2023/08/09晚）</h5></li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs js"><span class="hljs-keyword">const</span> &#123;url&#125; = <span class="hljs-title class_">JSON</span>.<span class="hljs-title function_">parse</span>(<span class="hljs-built_in">decodeURIComponent</span>(options.<span class="hljs-property">parameter</span>));<br></code></pre></td></tr></table></figure>

<h4 id="点击image标签携带URL"><a href="#点击image标签携带URL" class="headerlink" title="点击image标签携带URL"></a>点击image标签携带URL</h4><ul>
<li><h5 id="要给每个-lt-image-gt-标签添加-click-函数，以便点击不同的图片跳转到不同的页面，可以通过以下方法实现："><a href="#要给每个-lt-image-gt-标签添加-click-函数，以便点击不同的图片跳转到不同的页面，可以通过以下方法实现：" class="headerlink" title="要给每个 &lt;image&gt; 标签添加 click 函数，以便点击不同的图片跳转到不同的页面，可以通过以下方法实现："></a>要给每个 <code>&lt;image&gt;</code> 标签添加 click 函数，以便点击不同的图片跳转到不同的页面，可以通过以下方法实现：</h5></li>
</ul>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">image</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;img&quot;</span> <span class="hljs-attr">src</span>=<span class="hljs-string">&quot;&#123;&#123;item&#125;&#125;&quot;</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">&quot;刚刚&quot;</span> <span class="hljs-attr">mode</span>=<span class="hljs-string">&quot;widthFix&quot;</span> <span class="hljs-attr">bindtap</span>=<span class="hljs-string">&quot;handleImageTap&quot;</span> <span class="hljs-attr">data-url</span>=<span class="hljs-string">&quot;&#123;&#123;item&#125;&#125;&quot;</span>/&gt;</span><br></code></pre></td></tr></table></figure>

<ul>
<li><h5 id="在当前页面的-JS-文件中定义-handleImageTap-方法来处理点击事件"><a href="#在当前页面的-JS-文件中定义-handleImageTap-方法来处理点击事件" class="headerlink" title="在当前页面的 JS 文件中定义 handleImageTap 方法来处理点击事件"></a>在当前页面的 JS 文件中定义 <code>handleImageTap</code> 方法来处理点击事件</h5></li>
<li><h5 id="可以使用-wx-navigateTo-方法跳转到不同的页面并传递参数"><a href="#可以使用-wx-navigateTo-方法跳转到不同的页面并传递参数" class="headerlink" title="可以使用 wx.navigateTo 方法跳转到不同的页面并传递参数"></a>可以使用 <code>wx.navigateTo</code> 方法跳转到不同的页面并传递参数</h5></li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs js"><span class="hljs-title class_">Page</span>(&#123;<br>  <span class="hljs-title function_">handleImageTap</span>(<span class="hljs-params">e</span>) &#123;<br>    <span class="hljs-keyword">const</span> imageUrl = e.<span class="hljs-property">currentTarget</span>.<span class="hljs-property">dataset</span>.<span class="hljs-property">url</span>;<br>    <span class="hljs-comment">// 根据需要的逻辑处理点击事件，例如根据不同的 imageUrl 进行不同的跳转</span><br>    wx.<span class="hljs-title function_">navigateTo</span>(&#123;<br>      <span class="hljs-attr">url</span>: <span class="hljs-string">`/pages/detail?imageUrl=\$&#123;imageUrl&#125;`</span>,<br>    &#125;);<br>  &#125;,<br>&#125;);<br></code></pre></td></tr></table></figure>

<ul>
<li><h5 id="在-handleImageTap-方法中，使用-e-currentTarget-dataset-url-获取到点击的图片链接，然后根据需要的逻辑进行不同的跳转。"><a href="#在-handleImageTap-方法中，使用-e-currentTarget-dataset-url-获取到点击的图片链接，然后根据需要的逻辑进行不同的跳转。" class="headerlink" title="在 handleImageTap 方法中，使用 e.currentTarget.dataset.url 获取到点击的图片链接，然后根据需要的逻辑进行不同的跳转。"></a>在 <code>handleImageTap</code> 方法中，使用 <code>e.currentTarget.dataset.url</code> 获取到点击的图片链接，然后根据需要的逻辑进行不同的跳转。</h5></li>
<li><h5 id="请注意，上述代码是使用小程序原生的-wx-navigateTo-进行页面跳转，如果你使用的是框架或组件库，可能有不同的方法来实现页面跳转。（2023-08-09晚）"><a href="#请注意，上述代码是使用小程序原生的-wx-navigateTo-进行页面跳转，如果你使用的是框架或组件库，可能有不同的方法来实现页面跳转。（2023-08-09晚）" class="headerlink" title="请注意，上述代码是使用小程序原生的 wx.navigateTo 进行页面跳转，如果你使用的是框架或组件库，可能有不同的方法来实现页面跳转。（2023/08/09晚）"></a>请注意，上述代码是使用小程序原生的 <code>wx.navigateTo</code> 进行页面跳转，如果你使用的是框架或组件库，可能有不同的方法来实现页面跳转。（2023/08/09晚）</h5></li>
</ul>
<h4 id="实现点赞图片"><a href="#实现点赞图片" class="headerlink" title="实现点赞图片"></a>实现点赞图片</h4><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs html"><span class="hljs-comment">&lt;!-- 点赞量 --&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">view</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;like&quot;</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">van-icon</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;&#123;&#123;isLiked ? &#x27;like&#x27; : &#x27;like-o&#x27;&#125;&#125;&quot;</span> <span class="hljs-attr">color</span>=<span class="hljs-string">&quot;red&quot;</span> <span class="hljs-attr">bindtap</span>=<span class="hljs-string">&quot;handleIconClick&quot;</span>/&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">view</span>&gt;</span><br></code></pre></td></tr></table></figure>

<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs js"><span class="hljs-comment">// 点赞壁纸</span><br> <span class="hljs-title function_">handleIconClick</span>(<span class="hljs-params"></span>) &#123;<br>   <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">setData</span>(&#123;<br>     <span class="hljs-attr">isLiked</span>: !<span class="hljs-variable language_">this</span>.<span class="hljs-property">data</span>.<span class="hljs-property">isLiked</span>, <span class="hljs-comment">// 点击后取反</span><br>   &#125;);<br>   <span class="hljs-keyword">if</span>(<span class="hljs-variable language_">this</span>.<span class="hljs-property">data</span>.<span class="hljs-property">isLiked</span>)&#123;<br>     <span class="hljs-title class_">Toast</span>(<span class="hljs-string">&quot;已收藏~&quot;</span>)<br>   &#125;<span class="hljs-keyword">else</span>&#123;<br>     <span class="hljs-title class_">Toast</span>(<span class="hljs-string">&#x27;取消收藏~&#x27;</span>)<br>   &#125;<br> &#125;,<br></code></pre></td></tr></table></figure>

<h3 id="效果呈现"><a href="#效果呈现" class="headerlink" title="效果呈现"></a>效果呈现</h3><blockquote>
<p>2024年4月22日</p>
</blockquote>
<p>半年前尝试开发过第一个微信小程序，花费了二十天时间认真做功能实现.。当时为了开发这个小程序，还借鉴了不少相关小程序的页面排版，多方参照才最终定型了这版页面。那么最终的<strong>效果如下</strong>：</p>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20230908221852633.png" alt="image-20230908221852633"></p>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20230908221858146.png" alt="image-20230908221858146"></p>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20230908221905369.png" alt="image-20230908221905369"></p>
<h3 id="踩坑记录"><a href="#踩坑记录" class="headerlink" title="踩坑记录"></a>踩坑记录</h3><ul>
<li><h5 id="首先，能够正确获取到小程序的appID、appSecret："><a href="#首先，能够正确获取到小程序的appID、appSecret：" class="headerlink" title="首先，能够正确获取到小程序的appID、appSecret："></a>首先，能够正确获取到小程序的appID、appSecret：</h5></li>
</ul>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20230806111056970.png" alt="image-20230806111056970"></p>
<ul>
<li><h5 id="开发者工具的appID必须设置正确，否则会不可避免地出现-invalid-code-错误：（2023-08-06早）"><a href="#开发者工具的appID必须设置正确，否则会不可避免地出现-invalid-code-错误：（2023-08-06早）" class="headerlink" title="开发者工具的appID必须设置正确，否则会不可避免地出现 invalid code 错误：（2023/08/06早）"></a>开发者工具的appID必须设置正确，否则会不可避免地出现 invalid code 错误：（2023/08/06早）</h5></li>
</ul>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs json"><span class="hljs-punctuation">&#123;</span><span class="hljs-attr">&quot;errcode&quot;</span><span class="hljs-punctuation">:</span><span class="hljs-number">40029</span><span class="hljs-punctuation">,</span><span class="hljs-attr">&quot;errmsg&quot;</span><span class="hljs-punctuation">:</span><span class="hljs-string">&quot;invalid code, rid: 64cf07f9-36a4c687-09c960f0&quot;</span><span class="hljs-punctuation">&#125;</span><br></code></pre></td></tr></table></figure>

<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20230806110759499.png" alt="image-20230806110759499"></p>
<h2 id="公众号开通"><a href="#公众号开通" class="headerlink" title="公众号开通"></a>公众号开通</h2><blockquote>
<p>2024年4月22日</p>
</blockquote>
<p>今下午，我突然想要开通一个微信公众号，借此来激励我每天读书写作。那是因为最近开始慢慢回忆起<strong>小时候的乡村生活</strong>，写的东西渐渐多了起来。但总归是没时间没精力，写东西断断续续的，我对这样的写作现状很不满意。</p>
<p>于是下午看了很多相关公众号文章，计划近段时间就开启公众号文章写作计划：</p>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20240422153640539.png" alt="image-20240422153640539"></p>
<p>我快速回顾了前段时间里了解到的有关微信公众平台的信息，包括小程序开发、智能机器人对话（<a target="_blank" rel="noopener" href="https://www.nowcoder.com/discuss/353159057999601664?sourceSSR=users">动手做个 AI 机器人，帮我回消息！_牛客网 (nowcoder.com)</a>）这些，把这些快遗忘的知识捡起来。</p>
<p><strong>微信公众平台访问入口：<a target="_blank" rel="noopener" href="https://mp.weixin.qq.com/?token=&lang=zh_CN">微信公众平台 (qq.com)</a></strong></p>
<p>注册一个微信公众号，选择<strong>订阅号</strong>即可。</p>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20240422153221125.png" alt="image-20240422153221125"></p>
<p>但接下来的一步就让我止步于此了，我必须要提供一个<strong>未被微信公众平台注册过</strong>的邮箱</p>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20240422154009938.png" alt="image-20240422154009938"></p>
<p>详细要求可以看这里：<a target="_blank" rel="noopener" href="https://kf.qq.com/faq/120911VrYVrA161215zqaIJr.html">公众号注册提示“邮箱已被占用” (qq.com)</a></p>
<p>除了现在正在使用的 qq 邮箱外，去年写小程序时还用手机号申请了网易邮箱。但现在由于这个网易邮箱绑定了一个小程序，要想顺利开通微信公众号，目前只有两种解决办法：<strong>修改小程序登录邮箱</strong>和<strong>注销小程序</strong></p>
<p><img src="https://gitee.com/deng-2022/pictures/raw/master/images/image-20240422144343165.png" alt="image-20240422144343165"></p>
<p>虽然这个小程序是废稿，但毕竟是我开发的第一个微信小程序，未来可能还要继续优化呢。就这么注销了的话，本地的开发可能受到影响，怪可惜的。那最终的解决办法就是：<strong>今天晚上回去找我兄弟，让他注册一个网易邮箱，完事了我把小程序邮箱账号更换成他的，我开通的微信公众号就绑定我的网易邮箱吧。</strong></p>
<p>那么现在就开始研究研究今年年初搞过的微信智能 AI 机器人了，不知道当时怎么想的，竟然没有记录下代码是如何起来的。相关的开发文档也没有多少记录，只有运行效果，只好是我再继续摸索摸索。</p>
<blockquote>
<p>2024年4月23日</p>
</blockquote>
<p>很好，昨天下午总结了一番微信智能 AI 机器人的开发流程，晚上又让我的好兄弟注册了新的网易邮箱。</p>
<p>这下我就成功开通了微信公众号了。</p>
<h1 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h1>
                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/categories/%E5%B0%8F%E7%A8%8B%E5%BA%8F/" class="category-chain-item">小程序</a>
  
  
    <span>></span>
    
  <a href="/categories/%E5%B0%8F%E7%A8%8B%E5%BA%8F/%E9%A1%B9%E7%9B%AE/" class="category-chain-item">项目</a>
  
  
    <span>></span>
    
  <a href="/categories/%E5%B0%8F%E7%A8%8B%E5%BA%8F/%E9%A1%B9%E7%9B%AE/%E7%BB%8F%E9%AA%8C/" class="category-chain-item">经验</a>
  
  

  

  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/tags/%E7%BB%8F%E9%AA%8C/">#经验</a>
      
        <a href="/tags/%E9%A1%B9%E7%9B%AE/">#项目</a>
      
        <a href="/tags/%E5%B0%8F%E7%A8%8B%E5%BA%8F/">#小程序</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>小程序开发经验分享：踩坑指南与技巧总结</div>
      <div>http://example.com/2023/07/30/小程序开发经验分享：踩坑指南与技巧总结/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>Memory</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2023年7月30日</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>更新于</div>
          <div>2023年8月9日</div>
        </div>
      
      
        <div class="license-meta-item">
          <div>许可协议</div>
          <div>
            
              
              
                <a target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
                  <span class="hint--top hint--rounded" aria-label="BY - 署名">
                    <i class="iconfont icon-by"></i>
                  </span>
                </a>
              
            
          </div>
        </div>
      
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2023/08/02/PicMemories%20%E5%A3%81%E7%BA%B8%E5%88%86%E4%BA%AB%E5%B0%8F%E7%A8%8B%E5%BA%8F%20-%20%E5%BC%80%E5%8F%91%E6%96%87%E6%A1%A3/" title="PicMemories-开发文档">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">PicMemories-开发文档</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2023/07/30/%E4%B8%80%E6%96%87%E6%90%9E%E5%AE%9A%E7%BD%91%E7%AB%99%E4%B8%8A%E7%BA%BF%EF%BC%9A%E4%BB%8E%E9%9B%B6%E5%88%B0%E4%B8%80%E7%9A%84%E5%AE%9E%E6%88%98%E6%8C%87%E5%8D%97/" title="一文搞定网站上线：从零到一的实战指南">
                        <span class="hidden-mobile">一文搞定网站上线：从零到一的实战指南</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
  
  
    <article id="comments">
      

    </article>
  


          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header">
    <i class="iconfont icon-list"></i>
    <span>目录</span>
  </p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="https://hexo.fluid-dev.com/docs/guide/" target="_blank" rel="nofollow noopener"> <span>Memory | 个人文档站点</span> </a>
<i class="iconfont icon-love"></i> <a href="https://hexo.fluid-dev.com/docs/guide/" target="_blank" rel="nofollow noopener"> <span>配置指南 | Hexo Fluid 用户手册</span> </a>   
    </div>
  
  
    <div class="statistics">
  
  

  
    
      <span id="leancloud-site-pv-container" style="display: none">
        总访问量 
        <span id="leancloud-site-pv"></span>
         次
      </span>
    
    
      <span id="leancloud-site-uv-container" style="display: none">
        总访客数 
        <span id="leancloud-site-uv"></span>
         人
      </span>
    
    

  
</div>

  
  
    <!-- 备案信息 ICP for China -->
    <div class="beian">
  <span>
    <a href="http://beian.miit.gov.cn/" target="_blank" rel="nofollow noopener">
      京ICP证123456号
    </a>
  </span>
  
    
      <span>
        <a
          href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=12345678"
          rel="nofollow noopener"
          class="beian-police"
          target="_blank"
        >
          
            <span style="visibility: hidden; width: 0">|</span>
            <img src="/img/police_beian.png" alt="police-icon"/>
          
          <span>京公网安备12345678号</span>
        </a>
      </span>
    
  
</div>

  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>







  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.2/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init(Object.assign({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      scrollSmooth    : true,
      includeTitleTags: true,
      headingsOffset  : -boardTop,
    }, CONFIG.toc));
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }

    Fluid.events.registerRefreshCallback(function() {
      if ('tocbot' in window) {
        tocbot.refresh();
        var toc = jQuery('#toc');
        if (toc.length === 0 || !tocbot) {
          return;
        }
        if (toc.find('.toc-list-item').length > 0) {
          toc.css('visibility', 'visible');
        }
      }
    });
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.11/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));

    Fluid.events.registerRefreshCallback(function() {
      if ('anchors' in window) {
        anchors.removeAll();
        var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
        var res = [];
        for (var item of el) {
          res.push('.markdown-body > ' + item.trim());
        }
        if (CONFIG.anchorjs.placement === 'left') {
          anchors.options.class = 'anchorjs-link-left';
        }
        anchors.add(res.join(', '));
      }
    });
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/js/local-search.js" ></script>

  <script defer src="/js/leancloud.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
